package com.ruoyi.cust.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.cust.vo.CityModuleTreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cust.domain.CityModule;
import com.ruoyi.cust.service.ICityModuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模块Controller
 *
 * @author ruoyi
 * @date 2024-12-06
 */
@Api("资讯")
@RestController
@RequestMapping("/city/module")
public class CityModuleController extends BaseController {
    @Autowired
    private ICityModuleService cityModuleService;

    /**
     * 查询模块列表
     */
    @ApiOperation("查询模块列表")
    @PreAuthorize("@ss.hasPermi('city:module:list')")
    @GetMapping("/list")
    public TableDataInfo list(CityModule cityModule) {
        startPage();
        List<CityModule> list = cityModuleService.selectCityModuleList(cityModule); return getDataTable(list);
    }

    /**
     * 查询模块列表
     */
    @ApiOperation("查询模块树")
    @PreAuthorize("@ss.hasPermi('city:module:list')")
    @GetMapping("/moduleTree")
    public List<CityModuleTreeVo> moduleTree(CityModule cityModule) {
         return cityModuleService.moduleTree(cityModule);
    }

    /**
     * 导出模块列表
     */
    @ApiOperation("导出模块列表")
    @PreAuthorize("@ss.hasPermi('city:module:export')")
    @Log(title = "模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CityModule cityModule) {
        List<CityModule> list = cityModuleService.selectCityModuleList(cityModule); ExcelUtil<CityModule> util = new ExcelUtil<CityModule>(CityModule. class);
        util.exportExcel(response, list, "模块数据");
    }

    /**
     * 获取模块详细信息
     */
    @ApiOperation("获取模块详细信息")
    @PreAuthorize("@ss.hasPermi('city:module:query')")
    @GetMapping(value = "/{moduleId}")
    public AjaxResult getInfo(@PathVariable("moduleId") Long moduleId) {
        return success(cityModuleService.selectCityModuleByModuleId(moduleId));
    }

    /**
     * 新增模块
     */
    @ApiOperation("新增模块")
    @PreAuthorize("@ss.hasPermi('city:module:add')")
    @Log(title = "模块", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CityModule cityModule) {
        return toAjax(cityModuleService.insertCityModule(cityModule));
    }

    /**
     * 修改模块
     */
    @ApiOperation("修改模块")
    @PreAuthorize("@ss.hasPermi('city:module:edit')")
    @Log(title = "模块", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CityModule cityModule) {
        return toAjax(cityModuleService.updateCityModule(cityModule));
    }

    /**
     * 删除模块
     */
    @ApiOperation("删除模块")
    @PreAuthorize("@ss.hasPermi('city:module:remove')")
    @Log(title = "模块", businessType = BusinessType.DELETE)
    @DeleteMapping("/{moduleIds}")
    public AjaxResult remove(@PathVariable Long[] moduleIds) {
        return toAjax(cityModuleService.deleteCityModuleByModuleIds(moduleIds));
    }
}
